package com.yinpeng.cloud_gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableDiscoveryClient
public class CloudGatewayApplication {

    // 网关配置
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        System.out.println("config ok");
        return builder.routes()
                .route("client-a", r -> r.path("/client-a/**")
                        .filters(f -> f.stripPrefix(1))
                        .uri("lb://consul-client"))
                .build();
    }

    public static void main(String[] args) {
        SpringApplication.run(CloudGatewayApplication.class, args);
    }

}
